<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/10/23 0023
 * Time: 14:59
 */
namespace app\modules\api\controllers;
use app\modules\api\models\PublishForm;
use app\hejiang\BaseApiResponse;
use app\models\Publish;

class PublishController extends Controller{

 //发布需求
    public function actionIndex(){
        $form=new PublishForm();
        $form->title =\Yii::$app->request->get('title');
        $form->content =\Yii::$app->request->get('content');
        $form->type =\Yii::$app->request->get('type');
        $form->image =\Yii::$app->request->get('image');
        $form->create_time =time();
        $form->user_id = \Yii::$app->user->id;
        return new BaseApiResponse($form->save());
    }
//发布详情
    public function actionDetail(){
        $id=\yii::$app->request->post('id');
        if($id==null){
            return new BaseApiResponse(['code'=>1,'msg'=>"id不能为空"]);
        }
        $model = Publish::findOne([
            'id' => $id,
        ]);
       if ($model){
           return new BaseApiResponse(['code'=>0,'msg'=>"操作成功",'data'=>$model]);
       }
    }

    //发布列表
    public  function actionList(){

        $form = new PublishForm();
        $form->attributes = \Yii::$app->request->get();
        $form->user_id = 1;
      
        return new BaseApiResponse($form->search());


    }



}